home *** CD-ROM | disk | FTP | other *** search
- /*
- * Compile with:
- * cc string.o array.o dict.o cgilib.o ht71.c -o ht71.cgi
- */
-
- #include <stdio.h>
- #include "cgilib.h"
-
- /*
- * Configurable Constants
- * The default values may be overwriten from the C
- * compiler's command line.
- * Ex. on a UN*X system
- * cc -DSUBJECT="\"Poll Results\"" \
- * string.o array.o cict.o cgilib.o ht71.c -o ht71.cgi
- */
- #ifndef SENDMAIL
- # define SENDMAIL "/usr/bin/sendmail"
- #endif
- #ifndef TO
- # define TO "kgr"
- #endif
- #ifndef SUBJECT
- # define SUBJECT "Survey Results"
- #endif
- #ifndef BACK
- # define BACK "<A HREF=\"/kgr/book\">Back to my Homepage</A>"
- #endif
-
- /*
- * It is expected that values for the following field names will
- * be supplied via the CGI interface. The list is terminated
- * with a NULL.
- */
- static char *names[] = {
- "name", "email", "street", "city",
- "state", "zip", "rating", "comments",
- NULL
- };
-
-
- void main(int argc, char *argv[])
- {
- FILE *mail; /* pipe to stdin of sendmail */
- Dictionary dataDict = readParse();/* CGI parameters */
- int i; /* index into *names[] */
- char buf[100]; /* sendmail commandline buf */
- char *email; /* from email address */
- char *name; /* senders real name */
-
- /* Output the HTML content type */
- printf("Content-type: text/html\n\n");
-
- /* The -t causes the To: field to be read from standard
- * input instead of being expected on the command line.
- * The -oi prevents a dot on a line by itself from being
- * interpreted as a message terminator.
- */
- sprintf(buf,"%s -t -oi",SENDMAIL);
- mail = popen(buf,"w");
-
- email = dict_isKey(dataDict,"email") ?
- dict_valueForKey(dataDict,"email") : "";
-
- name = dict_isKey(dataDict,"name") ?
- dict_valueForKey(dataDict,"name") : "";
-
- /*
- * Output the mail header
- */
- fprintf(mail, "Reply-to: %s, (%s)\n", email, name);
- fprintf(mail, "From: %s, (%s)\n", email, name);
- fprintf(mail, "To: %s\n", TO);
- fprintf(mail, "Subject: %s\n\n", SUBJECT);
-
- /*
- * Output the mail body
- */
- for ( i = 0 ; names[i] ; i++ )
- {
- fprintf(mail,"<%s>\n",names[i]);
- if (dict_isKey(dataDict,names[i]))
- {
- fprintf(mail,"%s\n",
- dict_valueForKey(dataDict,names[i]));
- }
- fprintf(mail,"\n");
- }
-
-
- /*
- * Output the mail footer
- */
- fprintf(mail, "\n<REMOTE HOST>\n%s\n\n",
- getenv("REMOTE_HOST"));
-
- fprintf(mail, "\n<REMOTE ADDR>\n%s\n\n",
- getenv("REMOTE_ADDR"));
-
- fprintf(mail, "\n<USER AGENT>\n%s\n\n",
- getenv("HTTP_USER_AGENT"));
-
- /* Close the pipe, sending the mail */
- pclose(mail);
-
- /*
- * Generate HTML notification
- */
-
- printf("<HTML><BODY><H1>Your comments have been noted.<BR>");
- printf("Thank you for your time.<BR><BR>%s</H1>",BACK);
- printf("</BODY></HTML>");
-
- /* Free the dynamic memory associated with dataDict. */
- dict_free(dataDict);
-
- /* End the program */
- exit(0);
- }
-